package com.hermeneute.fsa;

import java.util.TreeSet;

public class FSTTransitionList extends TreeSet{
    FSTTransitionList(){
	super (new FSTTransitionComparator());
    }
    void addTransition(FSTTransition tr){
	if (!contains(tr)){
	    add(tr);
	}
    }
    void replaceTransition(FSTTransition tr){
	if (contains(tr)){
	    removeTransition(tr);
	    add(tr);
	}else{
	    add(tr);
	}
    }
    void removeTransition(FSTTransition tr){
	remove(tr);
    }

    boolean exists(FSTTransition tr){
	return ((FSTTransition)get(tr)).getState() == tr.getState();
    }

    FSTTransition get(FSTTransition tr){
	if (contains(tr)){
	    return (FSTTransition) tailSet((Object)tr).first();
	}else{
	    return null;
	}
    }

    FSTTransitionIterator getTransitions() {
	return new FSTTransitionIterator(iterator());
    }
}
